<script type="text/javascript">
	function func_list(id){
		$("#hidSubId").val(id);
		$("#main_form").prop("action", "/it_center/Videos/manageListVideos");
		return $("#main_form").submit();
	}			

	function func_edit(id){
		$("#hidId").val(id);
		$("#main_form").prop("action", "/it_center/Videos/edit");
		return $("#main_form").submit();
	}

	function func_add(){
		$("#main_form").prop("action", "/it_center/Videos/add");
		return $("#main_form").submit();
	}

	function func_delete(id){
		var r=confirm("Bạn muốn xóa video?")
		if (r==true){
			$("#hidId").val(id);
			$("#main_form").prop("action", "/it_center/Videos/delete");
			return $("#main_form").submit();
		}
	}
</script>
<section id="content" class="cols-a">
		<section class="news-a">
			<article>
			<header>
				<h2>Danh sách các videos tự học</h2>
			</header>
			<br/>
			<?php If (isset($listVideos)){?>
			<?php If (count($listVideos) > 0){?>
			<form method="POST" id="main_form">
				<input type="hidden" id="hidSubId" name="subId" value="<?php echo $selectedSubId;?>"/>
				<input type="hidden" id="hidId" name="id"/>
			</form>
				<div id="regist" >
					<a href="#" onclick="func_add()" class="regist" style="margin-left: 0px;">Thêm mới môn học</a>
				</div>
				<?php foreach ($listVideos as $video):?>
					<article>
					<br/>
					
						<header>
							<h3><a href="#" onclick="func_edit(<?php echo $video['Video']['m_video_id'];?>)"><?php echo $video['Video']['m_video_title']?></a></h3>
						</header>
						
							<p><?php echo html_entity_decode($video['Video']['m_video_descript'], ENT_QUOTES, 'utf-8'); ?></p>
						<a class="delete" style="margin-left: 0px;" onclick="func_delete(<?php echo $video['Video']['m_video_id'];?>)">Xóa video</a>
					</article>
				
				<?php endforeach; ?>
			
			<?php if ($pagerInfo['total_page'] > 1){ ?>
			<footer>
				<nav class="pagination-a">
					<?php if ($pagerInfo['start_page'] > 1){?>
						<p><a href="/it_center/Videos/index?sub_id=<?php echo $selectedSubId;?>&page_no=<?php echo $pagerInfo['page_no'] - 1;?>&start_page=<?php echo $pagerInfo['start_page'];?>&end_page=<?php echo $pagerInfo['end_page'];?>">Previous</a></p>
					<?php }?>
					<ol>
						<?php for($i = $pagerInfo['start_page']; $i <= $pagerInfo['end_page']; $i++){?>
							<li <?php if ($i = $pagerInfo['page_no']){?>class="active"<?php }?>><a href="/it_center/Videos/index?sub_id=<?php echo $selectedSubId;?>&page_no=<?php echo $i;?>&start_page=<?php echo $pagerInfo['start_page'];?>&end_page=<?php echo $pagerInfo['end_page'];?>"><?php echo $i;?></a></li>
						<?php }?>
					</ol>
					<?php if ($pagerInfo['end_page'] < $pagerInfo['total_page'] - 4){?>
						<p><a href="/it_center/Videos/index?sub_id=<?php echo $selectedSubId;?>&page_no=<?php echo $pagerInfo['page_no'] + 1;?>&start_page=<?php echo $pagerInfo['start_page'];?>&end_page=<?php echo $pagerInfo['end_page'];?>">Next</a></p>
					<?php }?>
				</nav>
			</footer>
			<?php }?>
			<?php }else{?>
				<article>
				<header>
					<h3>Hiện tại chưa có video tự học cho môn học này.<br/>Vui lòng thêm mới video.</h3>
				</header>
				<br/>
				<form method="POST" id="main_form">
					<div id="regist" >
						<a href="#" onclick="func_add()" class="regist" style="margin-left: 0px;">Thêm mới môn học</a>
					</div>
					<input type="hidden" id="hidSubId" name="subId" value="<?php echo $selectedSubId;?>"/>
				</form>
				</article>
			<?php }?>
			<?php } else {?>
				<article>
				<header>
					<h3>Vui lòng chọn môn học tại mục danh sách môn học.</h3>
				</header>
				<form method="POST" id="main_form">
					<input type="hidden" id="hidSubId" name="subId"/>
				</form>
				</article>
			<?php }?>
			
		</section>
		<aside>
			<h3>Danh Sách Môn Học</h3>
			<nav>
				<ul>
					<?php foreach ($subjects as $subject):?>						
					<li>
						<a href="#" onclick="func_list(<?php echo $subject['Subject']['sub_id'];?>)"><?php echo $subject['Subject']['sub_name'];?></a>
					</li>
					<?php endforeach;?>
				</ul>
			</nav>
		</aside>
	
</section>